﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YatuUI;

namespace Demo.PTGUI
{
    public partial class FrmRegister : Form
    {
        public FrmRegister()
        {
            InitializeComponent();
        }

        private void btnReg_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtLicence.Text))
            {
                MessageBox.Show("请输入注册码！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtLicence.Focus();
                return;
            }
            if (txtLicence.Text.Trim() == SoftReg.GetRNum())
            {
                var licence = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "licence.txt");
                File.WriteAllText(licence, txtLicence.Text.Trim());
                //Process.Start("reg.cmd");
                var res = MessageBox.Show("注册成功！点击确定自动重启软件", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (res == DialogResult.OK)
                {
                    Application.Restart();
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            else
            {
                MessageBox.Show("注册码错误！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtLicence.SelectAll();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void FrmRegister_Load(object sender, EventArgs e)
        {
            this.txtHardware.Text = SoftReg.GetMNum();
            txtLicence.Focus();
        }
    }
}
